﻿// <copyright file="LinkPropertyEditor.cs" company="City of Portland, BES-ASM">
// </copyright>
// <summary>LinkPropertyEditor Form</summary>

namespace BESASM.EMGAATS.UI
{
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using BESASM.EMGAATS.BusinessClasses;

  /// <summary>
  /// A form for editing link properties.
  /// </summary>
  public partial class LinkPropertyEditor : Form
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="LinkPropertyEditor"/> class.
    /// </summary>
    public LinkPropertyEditor()
    {
      this.InitializeComponent();

      foreach (var material in Enum.GetValues(typeof(Material)))
      {
        this.materialComboBox.Items.Add(material);
      }
    }

    /// <summary>
    /// Gets or sets the link to be edited.
    /// </summary>
    public ILink Link
    {
      get
      {
        return this.linkBindingSource.DataSource as ILink;
      }

      set
      {
        this.linkBindingSource.DataSource = null;

        this.crossSectionComboBox.Items.Clear();
        this.usNodeTextBox.Text = "<Null>";
        this.dsNodeTextBox.Text = "<Null>";

        if (value != null)
        {
          if (value.Network != null)
          {
            foreach (var crossSection in value.Network.CrossSections)
            {
              this.crossSectionComboBox.Items.Add(crossSection);
            }
          }

          if (value.USNode != null)
          {
            this.usNodeTextBox.Text = value.USNode.NodeName;
          }

          if (value.DSNode != null)
          {
            this.dsNodeTextBox.Text = value.DSNode.NodeName;
          }
        }

        this.linkBindingSource.DataSource = value;
      }
    }

    private void CancelButton_Click(object sender, EventArgs e)
    {
      this.Close();
    }
  }
}
